//
//  JWGRStudentVC.m
//  koubei
//
//  Created by 李彦宏 on 2018/4/20.
//  Copyright © 2018年 朱圳. All rights reserved.
//

#import "JWGRStudentVC.h"
#import "JWGRStuCell.h"
#import "JWGRStudHead.h"
#import "JWUserManager.h"
#import "JWGRUsermodel.h"
#import "SDUserModel.h"
#import "JWLookSDCtry.h"//查看学生详情


@interface JWGRStudentVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *StudenList;
@property (nonatomic, strong) JWGRUsermodel *Gmodel;
@property (nonatomic, strong) SDUserModel *SDmodel;
@end

@implementation JWGRStudentVC
//UItableView初始化
- (void)setupTable
{
    UITableView *tableView=[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    tableView.backgroundColor=[UIColor whiteColor];
    tableView.showsHorizontalScrollIndicator=NO;
    tableView.showsVerticalScrollIndicator=NO;
    tableView.dataSource=self;
    tableView.delegate=self;
    tableView.tableFooterView=[[UIView alloc]init];
tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    [self.view addSubview:tableView];
    self.tableView=tableView;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [EasyShowOptions sharedEasyShowOptions].lodingShowType =  LodingShowTypeTurnAround ;
    [EasyShowOptions sharedEasyShowOptions].textStatusType =  ShowTextStatusTypeStatusBar ;
    [EasyShowLodingView showLodingText:@""];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
       [self setData];
        [EasyShowLodingView hidenLoding];
    });
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self setupTable];
    self.Gmodel=[JWUserManager Gme];
   
    
    
    // Do any additional setup after loading the view.
}
#pragma -mark -----------------------------tableview datasource and delegate---------------------------------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _StudenList.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JWGRStuCell *cell=[JWGRStuCell cellwithTableview:tableView];
    cell.model=_StudenList[indexPath.row];
    
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    JWLookSDCtry *Stinfo=[[JWLookSDCtry alloc]init];
    
    self.SDmodel=self.StudenList[indexPath.row];
    Stinfo.title=[NSString stringWithFormat:@"%@的个人信息",self.SDmodel.name];
    
    [JWUserManager saveSD:self.SDmodel];
    [self.navigationController pushViewController:Stinfo animated:YES];
   
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 1;
}

#pragma -mark 头部的内容
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    JWGRStudHead *head=[[JWGRStudHead alloc]init];
    return head;
}
#pragma -mark —————————————————学员数据————————————————————
-(void)setData{
    if(self.Gmodel.ID==nil){
        self.Gmodel.ID=self.Gmodel.gid;
    }
    NSDictionary *dic=@{
                        @"jwid":JWid,
                        @"jwpassword":JWpassword,
                        @"gid":self.Gmodel.ID,
                        };
    
    [[AFNetworkTool shareManager]getJSONWithUrl:JW_LookGRSt parame:dic successData:^(id json) {
        [self.StudenList removeAllObjects];
        NSArray *arry=json[@"data"];
        __weak typeof(self) weakslf = self;
        for(int i=0;i<arry.count;i++){
                    self.SDmodel=[SDUserModel yy_modelWithJSON:arry[i]];
            [weakslf.StudenList addObject:weakslf.SDmodel];
                }
        if(arry.count==0){
                 [self.tableView removeFromSuperview];
                    KongDataView *kview=[KongDataView NilDataview];
                    kview.frame=self.view.frame;
                    [self.view addSubview:kview];
                }else{
                    [self.tableView reloadData];
                }
        
    } failure:^(NSError *error) {
        NSLog(@"--error--%@", error);
    }];
    
}

-(NSMutableArray *)StudenList{
    if(_StudenList==nil){
        _StudenList=[[NSMutableArray alloc]init];
    }
    return _StudenList;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
